﻿import xml.etree.ElementTree as et
from app.functions.funcs import formate_time
class xmlData:
	""" parsing raw xml data from xml string """
	def __init__(self,xmlstring=None):
		self.tree = et.fromstring(xmlstring)

	def getItemInfo(self):
		items = self.tree.getiterator("card")
		item_detail = []
		for item in items:
			try:
				title=item.findtext('title')
			except AttributeError:
				title=None
			try:
				identity=item.findtext('identity')
			except AttributeError:
				identity=None
			try:
				number=item.findtext('number')
			except AttributeError:
				number=None
			try:
				category=item.findtext('category')
			except AttributeError:
				category=None
			try:
				quantity=item.findtext('quantity')
			except AttributeError:
				quantity=None
			
			item_dict ={'title':title,
						'identity':identity,
						'number':number,
						'category':category,
						'quantity':quantity,}
			item_detail.append(item_dict)
		setattr(self,'itemsdb',item_detail)